package com.xiake.consultsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiake.consultsystem.pojo.po.ConsultRecord;
import com.xiake.consultsystem.mapper.ConsultRecordMapper;
import com.xiake.consultsystem.service.ConsultRecordService;
import com.xiake.consultsystem.pojo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Chen
 * @since 2022-11-13
 */
@Service
public class ConsultRecordServiceImpl  implements ConsultRecordService {

    @Autowired
    ConsultRecordMapper consultRecordMapper;

    /**
     * 学生预约的接口
     * @param date
     * @param timeId
     * @param counselorId
     * @return
     */
    @Override
    public Result makeAppoint(Date date, Long timeId, Long counselorId) {
        LambdaQueryWrapper<ConsultRecord> queryWrapper = new LambdaQueryWrapper<>();
        //根据日期 \ 时间id \ 咨询师Id 查找到唯一的一条咨询记录, 而后修改其中的 学生id, 和预约状态
        queryWrapper.eq(ConsultRecord::getDateTime,date);
        queryWrapper.eq(ConsultRecord::getTimeId,timeId);
        queryWrapper.eq( ConsultRecord::getCounselorId,counselorId);
        ConsultRecord consultRecord = new ConsultRecord();
        //此处设置成当前登录学生的id,后面需要修改
        Long tmp = 1L;
        consultRecord.setStudentId(tmp);
        consultRecord.setAppointState(0L);
        consultRecordMapper.update(consultRecord, queryWrapper);
        return Result.success("预约成功");
    }
}
